import http from '../../../common/httpUtil';
import * as types from './wareHouseMutationTypes';

const actions = {
  queryTransfers({commit}, {page, size}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.get(`portfolio/query/query_transfers?page=${page}&size=${size}`).then(data => {
      console.log(data)
      var wareHouse = data.content
      var totalCount = data.totalElements
      var currentPage = data.number
      console.log(wareHouse)
      commit(types.SYS_FILE_UPLOAD_QUERY_FILES_SUC, {wareHouse});
      commit(types.SYS_QUERY_WARES_TOTAL_SUC, {totalCount});
      commit(types.SYS_QUERY_WARES_CURRENT_SUC, {currentPage});
    });
  },
  addTransfers({commit}, {formData}) {
    return http.get(`portfolio/query/add_transfer?combinationCode=${formData.combinationCode}&combinationName=${formData.combinationName}&beginDate=${formData.beginDate}&endDate=${formData.endDate}&transferReason=${formData.transferReason}&transferContent=${formData.transferContent}`).then(data => {
      console.log(data)
      var newdata = formData
      commit(types.SYS_FILE_UPLOAD_SAVE_FILE_SUC, {newdata})
    });
  },
  editTransfers({commit}, {formData}) {
    // return http.post(`banklimit/update?id=${formData.id}&singleLimit=${formData.singleLimit}&dayLimit=${formData.dayLimit}&monthLimit=${formData.monthLimit}&state=${formData.state}`).then(data => {
    //   console.log(data)
    //   commit(types.SYS_FILE_UPLOAD_UPDATE_SUC, {formData})
    //   return data
    // });
    return http.get(`portfolio/query/update_transfer?warehouseId=${formData.warehouseId}&combinationCode=${formData.combinationCode}&combinationName=${formData.combinationName}&beginDate=${formData.beginDate}&endDate=${formData.endDate}&transferReason=${formData.transferReason}&transferContent=${formData.transferContent}`, formData).then(data => {
      console.log(data)
      commit(types.SYS_FILE_UPLOAD_UPDATE_SUC, {formData})
      return data
    });
  },
  delTransfers({commit}, {warehouseId}) {
    return http.get(`portfolio/query/delete_transfer?wareHouseId=${warehouseId}`).then(data => {
      commit(types.SYS_FILE_UPLOAD_DELETE_SUC, {warehouseId})
    });
  },
  querycombinationsList({commit}) {
    return http.get(`portfolio/query/query_all_combinations`).then(data => {
      var list = data
      console.log(data)
      commit(types.SYS_QUERY_COMBINATIONLIST_SUC, {list})
    });
  },

  queryTransfersfund({commit}, {warehouseId}) {
    commit(types.SYS_FILE_UPLOAD_QUERY_FILES_BEGIN);

    return http.get(`portfolio/query/query_warehouses?warehouseId=${warehouseId}`).then(data => {
      console.log(data)
      var wareHousefund = data
      commit(types.SYS_FILE_UPLOAD_QUERY_FUNDS_SUC, {wareHousefund});
    });
  },
  delTransfersfund({commit}, {mappingId}) {
    return http.get(`portfolio/query/delete_warehouse?mappingId=${mappingId}`).then(data => {
      commit(types.SYS_FUND_UPLOAD_DELETE_SUC, {mappingId})
    });
  },
  addTransfersfund({commit}, {formData}) {
    return http.get(`portfolio/query/add_one_warehouse?warehouseId=${formData.warehouseId}&fundType=${formData.fundType}&fundCode=${formData.fundCode}&fundName=${formData.fundName}&percentBefore=${formData.percentBefore}&percentNow=${formData.percentNow}`).then(data => {
      console.log(data)
      var newdata = formData
      commit(types.SYS_FUND_UPLOAD_SAVE_FILE_SUC, {newdata})
    });
  },
  editTransfersfund({commit}, {formData}) {
    // return http.post(`banklimit/update?id=${formData.id}&singleLimit=${formData.singleLimit}&dayLimit=${formData.dayLimit}&monthLimit=${formData.monthLimit}&state=${formData.state}`).then(data => {
    //   console.log(data)
    //   commit(types.SYS_FILE_UPLOAD_UPDATE_SUC, {formData})
    //   return data
    // });
    return http.get(`portfolio/query/update_warehouse?mappingId=${formData.mappingId}&warehouseId=${formData.warehouseId}&fundType=${formData.fundType}&fundCode=${formData.fundCode}&fundName=${formData.fundName}&percentBefore=${formData.percentBefore}&percentNow=${formData.percentNow}`, formData).then(data => {
      console.log(data)
      commit(types.SYS_FUND_UPLOAD_UPDATE_SUC, {formData})
      return data
    });
  }
};


export default actions;
